<?php
class MisCommon
{
	public static $recover_data;

	public static function diff($instance, $object, $type)
	{
		foreach ($object as $key=>$value) {
			if (property_exists($instance, $key)) {
				self::$recover_data[$type][$key] = $instance->$key;
				$instance->$key = $value;
			}
		}
	}

    public static function uniqueCast(&$casts)
    {
        $unique = array();
        foreach ($casts as $cast_role_id=>$arr) {
            if (!isset($unique[$cast_role_id])) {
                $unique[$cast_role_id] = array();
            }
            foreach ($arr as $key=>$cast) {
				if (in_array($cast, $unique[$cast_role_id])) {
					unset($casts[$cast_role_id][$key]);
				} else {
					$unique[$cast_role_id][] = $cast;
				}
            }
        }
    }

    public static function mergeCast(&$old_cast, array $casts)
    {   
		if (empty($casts)) {
			return FALSE;
		}

		foreach ($casts as $cast_role_id=>$sub_cast) {
			foreach ($sub_cast as $value) {
				$old_cast[$cast_role_id][] = $value;
			}
		}
    }

}
?>
